#include "ScnsLcd.c.h"

#if defined(SCNS_LCD_ENABLE)&&SCNS_LCD_ENABLE==1

#include "ScnsSt7789.h"
#include "ScnsSt7796.h"
#include "ScnsSt7735.h"
#include "ScnsIli9341.h"
#include "ScnsGt911.h"

#if defined(SCNS_ILI9341_ENABLE)&&SCNS_ILI9341_ENABLE==1
#define SECOND_ENUM                 SCNS_ILI9341_1
#define secondInit                  scnsIli9341Init
#define secondGetBorder             scnsIli9341GetBorder
#define secondSetBackgroundLight    scnsIli9341SetBackgroundLight
#define secondSetAddress            scnsIli9341SetAddress
#define secondWriteColor            scnsIli9341WriteColor
#define secondReadColor             scnsIli9341ReadColor
#define secondConfig                scnsIli9341LcdPhysicalConfig
#elif defined(SCNS_ST7789_ENABLE)&&SCNS_ST7789_ENABLE==1
#define SECOND_ENUM                 SCNS_ST7789_1
#define secondInit                  scnsSt7789Init
#define secondGetBorder             scnsSt7789GetBorder
#define secondSetBackgroundLight    scnsSt7789SetBackgroundLight
#define secondSetAddress            scnsSt7789SetAddress
#define secondWriteColor            scnsSt7789WriteColor
#define secondReadColor             scnsSt7789ReadColor
#define secondConfig                scnsSt7789LcdPhysicalConfig
#elif defined(SCNS_ST7796_ENABLE)&&SCNS_ST7796_ENABLE==1
#define SECOND_ENUM                 SCNS_ST7796_1
#define secondInit                  scnsSt7796Init
#define secondGetBorder             scnsSt7796GetBorder
#define secondSetBackgroundLight    scnsSt7796SetBackgroundLight
#define secondSetAddress            scnsSt7796SetAddress
#define secondWriteColor            scnsSt7796WriteColor
#define secondReadColor             scnsSt7796ReadColor
#define secondConfig                scnsSt7796LcdPhysicalConfig
#elif defined(SCNS_ST7735_ENABLE)&&SCNS_ST7735_ENABLE==1&&SCNS_BSP_LCD_PHYSICAL_DEVICE_MAX==1
#define SECOND_ENUM                 SCNS_ST7735_1
#define secondInit                  scnsSt7735Init
#define secondGetBorder             scnsSt7735GetBorder
#define secondSetBackgroundLight    scnsSt7735SetBackgroundLight
#define secondSetAddress            scnsSt7735SetAddress
#define secondWriteColor            scnsSt7735WriteColor
#define secondReadColor             scnsSt7735ReadColor
#define secondConfig                scnsSt7735LcdPhysicalConfig
#else
#error
#endif
#if SCNS_BSP_LCD_PHYSICAL_DEVICE_MAX==1

const ScnsBspLcdPhysicalConfig scnsBspLcdPhysicalConfig[SCNS_BSP_LCD_PHYSICAL_DEVICE_MAX]={
        secondConfig(0,0),
};

#elif SCNS_BSP_LCD_PHYSICAL_DEVICE_MAX==2

const ScnsBspLcdPhysicalConfig scnsBspLcdPhysicalConfig[SCNS_BSP_LCD_PHYSICAL_DEVICE_MAX]={
    scnsSt7735LcdPhysicalConfig(0,0),
    secondConfig(160,0),
};

#else
#error
#endif
#if SCNS_BSP_LCD_PHYSICAL_DEVICE_MAX==1

ScnsStatus scnsBspLcdInit(void)
{
    return secondInit(SECOND_ENUM);
}

Point scnsBspLcdGetBorder(uint8 pD)
{
    return secondGetBorder(SECOND_ENUM);
}

ScnsStatus scnsBspLcdSetBackgroundLight(ScnsLcdBackgroundLightStatus status)
{
    scnsCheckStatus(secondSetBackgroundLight(SECOND_ENUM,status));
    return SCNS_STATUS_OK;
}

ScnsStatus scnsBspLcdSetAddress(uint8 pd,Point plu,Point prd,uint8 write)
{
    scnsCheckStatus(secondSetAddress(SECOND_ENUM,plu,prd,write));
    return SCNS_STATUS_OK;
}

ScnsStatus scnsBspLcdWriteColor(uint8 pd,void*buf,uint32 n,uint8 last,ScnsLock*lock)
{
    scnsCheckStatus(secondWriteColor(SECOND_ENUM,buf,n,last,lock));
    return SCNS_STATUS_OK;
}

ScnsStatus scnsBspLcdReadColor(uint8 pd,void*buf,uint32 n,uint8 last,ScnsLock*lock)
{
    scnsCheckStatus(secondReadColor(SECOND_ENUM,buf,n,last,lock));
    return SCNS_STATUS_OK;
}

#elif SCNS_BSP_LCD_PHYSICAL_DEVICE_MAX==2

ScnsStatus scnsBspLcdInit(void)
{
    scnsCheckStatus(scnsSt7735Init(SCNS_ST7735_1));
    scnsCheckStatus(secondInit(SECOND_ENUM));
    
    return SCNS_STATUS_OK;
}

Point scnsBspLcdGetBorder(uint8 pD)
{
    switch(pD)
    {
        case 0:return scnsSt7735GetBorder(SCNS_ST7735_1);
        case 1:return secondGetBorder(SECOND_ENUM);
    }
    return (Point){0,0};
}

ScnsStatus scnsBspLcdSetBackgroundLight(ScnsLcdBackgroundLightStatus status)
{
    scnsCheckStatus(scnsSt7735SetBackgroundLight(SCNS_ST7735_1,status));
    scnsCheckStatus(secondSetBackgroundLight(SECOND_ENUM,status));
    return SCNS_STATUS_OK;
}

ScnsStatus scnsBspLcdSetAddress(uint8 pd,Point plu,Point prd,uint8 write)
{
    switch(pd)
    {
        case 0: return scnsSt7735SetAddress(SCNS_ST7735_1,plu,prd,write);
        case 1: return secondSetAddress(SECOND_ENUM,plu,prd,write);
    }
    return SCNS_STATUS_FAILED;
}

ScnsStatus scnsBspLcdWriteColor(uint8 pd,void*buf,uint32 n,uint8 last,ScnsLock*lock)
{
    switch(pd)
    {
        case 0: return scnsSt7735WriteColor(SCNS_ST7735_1,buf,n,last,lock);
        case 1: return secondWriteColor(SECOND_ENUM,buf,n,last,lock);
    }
    scnsCheckStatus(secondWriteColor(SECOND_ENUM,buf,n,last,lock));
    return SCNS_STATUS_FAILED;
}

ScnsStatus scnsBspLcdReadColor(uint8 pd,void*buf,uint32 n,uint8 last,ScnsLock*lock)
{
    switch(pd)
    {
        case 0: return scnsSt7735ReadColor(SCNS_ST7735_1,buf,n,last,lock);
        case 1: return secondReadColor(SECOND_ENUM,buf,n,last,lock);
    }
    return SCNS_STATUS_FAILED;
}

#else
#error
#endif
#endif